<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>文章中心--->发布文章</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${ctxPath}/static/manage/css/x-admin.css" media="all">
    <script src="${ctxPath}/static/manage/js/jquery.js"></script>
    <script src="${ctxPath}/static/manage/layui/layui.js"></script>
    <script src="${ctxPath}/static/manage/js/x-layui.js" charset="utf-8"></script>
</head>
<body>
<form class="layui-form" id="formupdate">
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>电脑名称</label>
        <div class="layui-input-inline">
            <input type="text" id="dname" name="dname" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>电脑类型</label>
        <div class="layui-input-inline">
            <select name="pid" id="pid">　
                <option value="0">-请选择-
                <option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>电脑颜色</label>
        <div class="layui-input-inline">
            <input type="text" id="color" name="color" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>生产日期</label>
        <div class="layui-input-inline">
            <input type="text" height="150px" id="createTime" name="createTime" class="layui-input"
                   placeholder="yyyy-MM-dd HH:mm:ss">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>售出日期</label>
        <div class="layui-input-inline">
            <input type="text" height="150px" id="shellTime" name="shellTime" class="layui-input"
                   placeholder="yyyy-MM-dd HH:mm:ss">
        </div>
    </div>
    <button class="layui-btn" type="button" lay-filter="add" lay-submit="">添加</button>
</form>
</body>
</html>

<script type="text/javascript">

    layui.use(['form',  'upload','laydate', 'layer'], function () {
        var $ = layui.$, upload = layui.upload, laydate = layui.laydate, form = layui.form;

        $(function () {
            $.ajax({
                type: 'post',
                url: '/manage/computerDetails/computerType',
                success: function (res) {
                    if (res.length > 0) {
                        for (var i = 0; i <= res.length; i++) {
                            $("#pid").append("<option value='" + res[i].id + "'>" + res[i].name + "</option>")
                            form.render();
                        }
                    }
                }
            })
        });

        laydate.render({
            elem: '#createTime'
            , type: 'datetime'
        });

        laydate.render({
            elem: '#shellTime'
            , type: 'datetime'
        });

        // 监听提交
        form.on('submit(add)', function () {
            if ($("#dname").val().trim() == "" || $("#dname").val().trim().length < 0) {
                alert("电脑名称不能为空");
                return false;
            }
            if ($("#color").val() == "" || $("#color").val().length < 0) {
                alert("电脑颜色不能为空");
                return false;
            }
            if ($("#createTime").val() == "" || $("#createTime").val().length < 0) {
                alert("电脑生产日期不能为空");
                return false;
            }
            if ($("#shellTime").val() == "" || $("#shellTime").val().length < 0) {
                alert("电脑出售日期不能为空");
                return false;
            }
          /*  // 添加文件 上传服务器
          upload.render({
                elem: '#uploadFile',
                size: 5000,
                exts: 'jpg|png|gif',
                url: '/manage/computerDetails/computerDetailsAddPicture',
                done: function(result){
                    layer.closeAll('loading');
                    alert(result.data);
                    window.location.reload();
                },
                error: function(result){
                    layer.closeAll('loading');
                    alert(result.data);
                    window.location.reload();
                }
            });*/


            $.ajax({
                url: '/manage/computerDetails/computerDetailsAdd',
                type: 'post',
                data: $("#formupdate").serialize(),
                success: function (result) {
                    alert(result);
                    window.parent.location.reload();
                },
                error: function (result) {
                    alert("失败？请及时告知开发人员" + result);
                    window.parent.location.reload();
                }
            });
        });
    });
</script>